// 2025/08/15
// Author: Forever
#include <bits/stdc++.h>
#define lowbit(x) (x & -x)
#define int long long
using namespace std;

int n, m, t[100005], a[100005];
vector<int> v[500005];

void build()
{
    for (int i = 1; i <= n; ++i) {
        t[i] += a[i];
        if (i + lowbit(i) <= n)
            t[i + lowbit(i)] += t[i];
    }
}

int query(int x, int y)
{
    x--;
    int res1 = 0, res2 = 0;
    while (x)
        res1 += t[x], x -= lowbit(x);
    while (y)
        res2 += t[y], y -= lowbit(y);
    return res2 - res1;
}

void update(int x, int v)
{
    while (x <= n)
        t[x] += v, x += lowbit(x);
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    build();
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j * j <= a[i]; ++j)
            if (a[i] % j == 0) {
                v[j].push_back(i);
                if (j * j != a[i])
                    v[a[i] / j].push_back(i);
            }
    }
    for (int i = 1; i <= m; ++i) {
        int op, x, y, z;
        cin >> op >> x >> y;
        if (op == 1) {
            cin >> z;
            if (z == 1 || v[z].empty())
                continue;
            auto l = lower_bound(v[z].begin(), v[z].end(), x);
            auto r = upper_bound(v[z].begin(), v[z].end(), y);
            if (l == v[z].end())
                continue;
            vector<vector<int>::iterator> t;
            for (auto j = l; j != r; ++j) {
                if (a[*j] % z)
                    continue;
                update(*j, a[*j] / z - a[*j]);
                a[*j] /= z;
                if (a[*j] % z)
                    t.push_back(j);
            }
            if (!t.empty())
                for (int j = t.size() - 1; j >= 0; j--)
                    v[z].erase(t[j]);
        } else {
            cout << query(x, y) << "\n";
        }
    }
    return 0;
}